跳到主要内容

HUD 元素

相关源文件

目的与范围

本页记录在玩法过程中为玩家提供实时反馈的 HUD(heads-up display)组件。这些 UI 元素会随时间更新,用于展示技能冷却、Boss 血条、伤害数字与玩家状态等关键信息。

关于模态 UI(背包、暂停菜单)请参见 InventoryLayer。关于触发 UI 更新的输入处理请参见 GameInputController。关于整体 UI 状态管理请参见 GameUIController


HUD 组件概览

HUD 系统由多个相互独立的组件组成:它们从游戏实体读取数据,并展示实时信息:

组件用途更新频率关键依赖
SkillBar展示主动技能槽位及冷却遮罩每帧SkillComponentPlayerCharacter
BossHealthBar展示 Boss HP、破韧条、连击伤害统计每帧CharacterBaseAttributeComponent
伤害数字伤害/治疗数值的浮动文字伤害事件触发CharacterBase::showDamageNumber()
PlayerStatusBar玩家 HP/MP/XP 条(不在本页提供的文件列表中)每帧PlayerCharacterAttributeComponent
交互提示传送门/NPC 提示(在架构中被引用)上下文敏感GameUIController

来源Adventure-King/Classes/UI/SkillBar.h L1-L412

Adventure-King/Classes/UI/BossHealthBar.h L1-L131

Adventure-King/Classes/Character/Base/CharacterBase.cpp L378-L429


架构:HUD 组件关系

字体加载优化:

// Source: CharacterBase.cpp:394-396
std::call_once(s_damageFontCheckOnce, []() {
s_damageFontExists = FileUtils::getInstance()->isFileExist(DEFAULT_DAMAGE_FONT_PATH);
});

字体是否存在的检查使用 std::call_once,避免每次产生伤害时都进行重复 I/O。对于战斗中高频受击的场景,这对性能非常关键。

来源Adventure-King/Classes/Character/Base/CharacterBase.cpp L378-L458


视觉参数

伤害数字:

  • 颜色: 暴击:Color3B(255, 50, 50)(亮红),普通:Color3B(255, 200, 50)(黄)
  • 字体大小: 暴击 28,普通 22
  • 描边: 黑色,2px
  • 位置: 角色包围盒 getMidX()getMaxY(),叠加随机偏移:水平 [-15, +15],垂直 [20, 30]
  • 动画: 0.8s 上移 60px + 0.5s 淡出(同时进行)
  • Z 序: 9999(总在最前)

治疗数字:

  • 颜色: Color3B(50, 255, 50)(绿)
  • 字体大小: 22
  • 格式: "+%.0f"
  • 动画: 0.8s 上移 40px + 0.4s 淡出

来源Adventure-King/Classes/Character/Base/CharacterBase.cpp L378-L458


PlayerStatusBar(玩家状态条)

注意: PlayerStatusBar 未包含在本页提供的文件列表中,但在架构图中被引用。根据其他 HUD 组件的模式推测,它可能:

  1. 通过 bindPlayer() 绑定 PlayerCharacter
  2. 通过 getCurrentHP()getCurrentMP() 读取 HP/MP
  3. 通过 getExperience()getLevel() 读取 XP/等级
  4. 使用类似 BossHealthBar 的分层条渲染
  5. GameUIController::update() 每帧驱动更新

具体实现请以实际 PlayerStatusBar 源码文件为准。


交互提示

交互提示(传送门/NPC 提示)在高层架构中被提及:

  • GameUIController 管理
  • 上下文敏感显示(当 isAtGateisAtNpc 为 true 时显示)
  • GameUIController::update() 读取临近标记并更新

具体实现请查看 GameUIController 源码文件。


HUD 更新流程汇总

要点:

  • SkillBar 每帧更新以跟踪冷却进度
  • BossHealthBar 每帧更新,但仅在伤害事件时触发动画
  • 伤害/治疗数字 在事件发生时立刻生成,不依赖逐帧更新
  • 所有 HUD 组件都采用从实体拉取读取(pull-based)的方式,而不是推送回调

来源Adventure-King/Classes/UI/SkillBar.cpp L147-L210

Adventure-King/Classes/UI/BossHealthBar.cpp L257-L344

Adventure-King/Classes/Character/Base/CharacterBase.cpp L148-L248